package com.ytjj.qmyx.mall.controller;

import com.ytjj.qmyx.mall.utils.wx.WXBizJsonMsgCrypt;
import com.ytjj.qmyx.mall.utils.wx.WXBizMsgCryptManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;


@RefreshScope
@RestController
@RequestMapping("/weCat")
@Slf4j
public class WxController {

    @GetMapping("/attestation")
    public @ResponseBody
    String valid(@RequestParam(value = "msg_signature") String signature,
                 @RequestParam(value = "timestamp") String timestamp,
                 @RequestParam(value = "nonce") String nonce,
                 @RequestParam(value = "echostr") String echostr) throws Exception {

        String sEchoStr = "";
        WXBizJsonMsgCrypt wxcpt = WXBizMsgCryptManager.getChatWXBizMsgCrypt();
        try {
            sEchoStr = wxcpt.VerifyURL(signature, timestamp, nonce, echostr);
            System.out.println("sEchoStr : " + sEchoStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sEchoStr;
    }
}
